import { Controller, Get, Post, Body, Query, Patch, Param, Delete, UseGuards } from '@nestjs/common'
import { VisitService } from './visit.service'
import { CreateVisitDto } from './dto/create-visit.dto'
import { UpdateVisitDto } from './dto/update-visit.dto'
import { AuthGuard } from '@nestjs/passport'

@Controller('visit')
@UseGuards(AuthGuard('jwt'))
export class VisitController {
    constructor(private readonly visitService: VisitService) { }

    @Post()
    create(@Body() createVisitDto: CreateVisitDto) {
        return this.visitService.create(createVisitDto);
    }

    @Get()
    findAll(@Query() urlQuery: { country?: string, province?: string, city?: string, pageIndex: string, pageSize: string }) {
        const query = {
            country: urlQuery.country || undefined,
            province: urlQuery.province || undefined,
            city: urlQuery.city || undefined,
            pageIndex: +urlQuery.pageIndex,
            pageSize: +urlQuery.pageSize
        }
        return this.visitService.findAll(query);
    }

    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.visitService.findOne(+id);
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateVisitDto: UpdateVisitDto) {
        return this.visitService.update(+id, updateVisitDto);
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.visitService.remove(+id);
    }
}
